<?php

/**
 * @author dungdhs@gmail.com
 * @copyright 2012
 */

function __category_load($cat_type=0){
  static $aCat;
  global $database;
  
  if (!isset($aCat[$cat_type])){
    if ($cat_type==0) $res = $database->db_query("SELECT * FROM categories ORDER BY cat_weight ASC");
    else $res = $database->db_query("SELECT * FROM categories WHERE cat_type=%d ORDER BY cat_weight ASC", $cat_type);
    
    while ($cat = $database->db_fetch_assoc($res)){
      $aCat[$cat_type][$cat['cat_id']] = $cat['cat_name'];
    }
  } 
  
  return $aCat[$cat_type];
}

function __category_get($cat_id){
  static $aCat;
  global $database;
  
  if (!isset($aCat[$cat_id])){
    $res = $database->db_query("SELECT * FROM categories WHERE cat_id=%d LIMIT 1", $cat_id);
    $aCat[$cat_id] = $database->db_fetch_assoc($res);
  }
  
  return $aCat[$cat_id];
}

?>